<template>
  <div class="header">
    <div class="name">
      <i class="iconfont">&#xe61d;</i>
      设备管理系统
    </div>
    <div class="user">
      <el-dropdown @command="userHandle">
        <el-button class="user-btn" command="toLogin">
          <i class="iconfont">&#xe8c8;</i>
          {{this.$store.state.user || username}}
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="logout">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
export default {
  name: "HomeHeader",
  props:['username'],
  methods: {
    userHandle(command) {
      if(command == 'logout') {
        localStorage.removeItem("token")
        this.$router.push('/')
      }
    }
  },
}
</script>

<style lang="less">
.header {
  height: 60px;
  display: flex;
  color: #fff;
  font-size: 16px;
  align-items: center;
  justify-content: space-between;
  background-color: #0079c4;

  .name {
    font-weight: bold;

    i {
      margin: 0 20px;
    }
  }

  .user {
    margin-right: 24px;
    .user-btn {
      border: 0;
      color: #fff;
      background-color: transparent;
    }
  }
}
</style>